import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class PersonSortable2 {
	private String name;
	private int age;

	public PersonSortable2(String name, int age) {
		super();
		this.name = name;
		this.age = age;
	}
    
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	@Override
	public String toString() {
		return name + "-" + age;
	}
}

class NameComparator implements Comparator<PersonSortable2> {

	@Override
	public int compare(PersonSortable2 p1, PersonSortable2 p2) {
		// TODO Auto-generated method stub
			return p1.getName() .compareTo(p2.getName()) ;
	}
}

 class AgeComparator implements Comparator<PersonSortable2> {

	@Override
	public int compare(PersonSortable2 p1,PersonSortable2 p2) {
		// TODO Auto-generated method stub
		
			return p1.getAge()-p2.getAge();
	}
}



public class Main3{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String name;
		int age;
		PersonSortable2[] p = new PersonSortable2[n];
		for (int i = 0; i < n; i++) {
			name = sc.next();
			age = sc.nextInt();
			p[i] = new PersonSortable2(name, age);
		}
		Arrays.sort(p,new NameComparator());
//		Arrays.sort(p,(p1,p2)->p1.getName().compareTo(p2.getName()));
        System.out.println("NameComparator:sort");
        for (PersonSortable2 personSortable : p) {
			System.out.println(personSortable);
		}
        Arrays.sort(p,new AgeComparator());
//        Arrays.sort(p,(p1,p2)->p1.getAge()-p2.getAge());
        System.out.println("AgeComparator:sort");
        for (PersonSortable2 personSortable : p) {
        	System.out.println(personSortable);
		}
        System.out.println(Arrays.toString(NameComparator.class.getInterfaces()));
        System.out.println(Arrays.toString(AgeComparator.class.getInterfaces()));
	}
	 

}
